package com.tonoinfo.convert;

import com.tonoinfo.dto.UserDTO;
import com.tonoinfo.entity.User;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * 用户转换
 * @author shuang.cheng
 * @date 2022/5/7
 */
@Mapper(componentModel = "spring", uses = { RoleConvert.class })  //实质就是给生成的类加了@Component
public interface UserConvert {

    /**
     * User转成UserDTO
     * @param user
     * @return UserDTO
     */
    @Mapping(source = "userName", target = "nickName")
    @Mapping(source = "power", target = "power", numberFormat = "#.##")
    @CommonConvert
    UserDTO user2UserDTO(User user);

    /**
     * UserDTO转成User
     * @InheritInverseConfiguration: 继承上面的反转配置
     * @param userDTO
     * @return User
     */
    @InheritInverseConfiguration(name = "user2UserDTO")
    User userDTO2User(UserDTO userDTO);
}
